package fnord.jovian.tango;

import java.awt.Graphics2D;
import java.util.Vector;

import fnord.illuminati.card.Connection;
import fnord.jovian.TheBoard;
import fnord.jovian.tango.TheAssemblyLayout.TheAssemblyOrientation;

public class TheControlMenu extends TheMenu {

	
	public TheControlMenu(TheBoard board) {
	    super(300, 300, board);
		_mask = null;
		TheAssemblyLayout layout = new TheAssemblyLayout(TheAssemblyOrientation.VERTICAL);
		setTheLayout(layout);
		this.addComponent(new TheButton("North", 200, 30, new TheDirectionListener(0)));
		this.addComponent(new TheButton("East", 200, 30, new TheDirectionListener(1)));
		this.addComponent(new TheButton("South", 200, 30, new TheDirectionListener(2)));
		this.addComponent(new TheButton("West", 200, 30, new TheDirectionListener(3)));
		this.addComponent(new TheButton("Cancel Attack", 200, 30, new TheCancelListener()));
	}
	
	public void setButtons(Connection[] points) {
		_objects = new Vector<TheObject>();
		for (int i = 0; i < points.length; i++) {
			switch(points[i]) {
			case WEST:
				this.addComponent(new TheButton("North", 200, 30, new TheDirectionListener(0)));
				break;
			case SOUTH:
				this.addComponent(new TheButton("West", 200, 30, new TheDirectionListener(3)));
				break;
			case EAST:
				this.addComponent(new TheButton("South", 200, 30, new TheDirectionListener(2)));
				break;
			case NORTH:
				this.addComponent(new TheButton("East", 200, 30, new TheDirectionListener(1)));
				break;
			}
		}
		this.addComponent(new TheButton("Cancel Attack", 200, 30, new TheCancelListener()));
	}
	
	public void paint(Graphics2D g) {
		setSize(300, 100 + 50*(_objects.size()-1));
		super.paint(g);
	}
	
	private class TheCancelListener implements TheListener {
		public void doAction() {
			_board.cancelAction();
		}
	}
	
	private class TheDirectionListener implements TheListener {
		private Connection _dir;
		public TheDirectionListener(int dir) {
			switch(dir) {
			case 0:
				_dir = Connection.WEST;
				break;
			case 1:
				_dir = Connection.NORTH;
				break;
			case 2:
				_dir = Connection.EAST;
				break;
			case 3:
				_dir = Connection.SOUTH;
			}
		}
        public void doAction() {
			_board.sendAttack(_dir);
        }
	}
}
